﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Data;
using LotteryVote.Entity;
using LotteryVote.Utility;

namespace LotteryVote.Logic
{
    public class DefaultUpperLimitFacade
    {
        private DefaultUpperLimitDataAccess _daDefaultUpperLimit;
        internal DefaultUpperLimitDataAccess DaDefaultUpperLimit
        {
            get
            {
                if (_daDefaultUpperLimit == null)
                    _daDefaultUpperLimit = new DefaultUpperLimitDataAccess();
                return _daDefaultUpperLimit;
            }
            set
            {
                _daDefaultUpperLimit = value;
            }
        }

        private GamePlayWayDataAccess _daGamePlayWay;
        internal GamePlayWayDataAccess DaGamePlayWay
        {
            get
            {
                if (_daGamePlayWay == null)
                    _daGamePlayWay = new GamePlayWayDataAccess();
                return _daGamePlayWay;
            }
            set
            {
                _daGamePlayWay = value;
            }
        }

        /// <summary>
        /// 初始化投注上限默认值.
        /// </summary>
        /// <param name="limitAmount">The limit amount.</param>
        public void InitDefaultUpperLimit(decimal limitAmount)
        {
            var allGamePlayWay = DaGamePlayWay.GetAllGamePlayWay();
            int notIncludeId = (int)PlayWayEnum.HeadAndLast;
            var insertGamePlayWay = allGamePlayWay.Where(it => it.PlayWay.WayId != notIncludeId);  //不包含头尾
            DaDefaultUpperLimit.ExecuteWithTransaction(() =>
            {
                foreach (var gpw in insertGamePlayWay)
                {
                    DefaultUpperLimit limit = new DefaultUpperLimit
                    {
                        GamePlayWayId = gpw.Id,
                        LimitAmount = limitAmount
                    };
                    DaDefaultUpperLimit.Insert(limit);
                }
            });
        }
    }
}
